package com.sjd.web.controller.common;

import com.sjd.common.core.controller.BaseController;
import com.sjd.common.core.domain.AjaxResult;
import com.sjd.mall.domain.dto.order.WebOrderStatsResponseDTO;
import com.sjd.mall.service.order.WebOrderService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 首页数据采集
 *
 * @author maple
 */
@RestController
@RequestMapping("/home")
@AllArgsConstructor
public class HomeController extends BaseController {

    private final WebOrderService webOrderService;

    @GetMapping("/data")
    public AjaxResult homeData() {
        Map<String, Object> resultMap = new HashMap<>(4);
        WebOrderStatsResponseDTO datas = webOrderService.stats();
        // 当日商城订单总金额
        resultMap.put("curDayMallOrderAmount", datas.getGoodsTotalOrderAmount());
        // 当日商城订单总数
        resultMap.put("curDayMallOrderCount", datas.getGoodsTotalOrderCount());
        // 当日课程订单总数
        resultMap.put("curDayCourseOrderCount", datas.getCourseTotalOrderCount());
        // 当日娱乐订单总数
        resultMap.put("curDayHappyOrderCount", datas.getFunTotalOrderCount());
        return AjaxResult.success(resultMap);
    }
}
